const app = getApp()
let qCloud = require("../../../index.js");

Page({
    /** 页面的初始数据 */
    data: {
        imgPath: qCloud.config.STATIC_IMAGE_PATH,
        processList: []
    },

    // 跳转-详情页面
    detailsTap(e) {
        let self = this
        let index = e.currentTarget.dataset.index;
        let enterprise = self.data.processList[index];
        wx.navigateTo({
            url: "/pages/enterprise/procedure/adds?processId=" + enterprise.processId,
        });
    },

    // 跳转-新增页面
    addsTap(e) {
        wx.navigateTo({
            url: "/pages/enterprise/procedure/adds",
        });
    },

    /**长按删除*/
    deletedTap: function (e) {
        let self = this;
        wx.showModal({
            content: '确定要删除吗？',
            success(res) {
                if (res.confirm) {
                    let params = {
                        processId: e.currentTarget.dataset.id
                    };
                    app.fetchApis(self, qCloud.api.common_deleteProcess, params, "POST", function (e) {
                        if (e.data.code == 200) {
                            self.queryProcessList();
                        }
                    });
                } else if (res.cancel) {
                    self.queryProcessList();
                }
            }
        })
    },

    /** 生命周期函数--监听页面加载 */
    onLoad: function (options) {
        let self = this;
        // 查询工序列表
        self.queryProcessList();
    },

    /** 查询工序列表 */
    queryProcessList: function (e) {
        let self = this;
        app.fetchApis(self, qCloud.api.common_queryProcessList, {}, "POST", function (e) {
            let result = e.data;
            if (result.code == 200) {
                let data = result.data;
                self.setData({
                    processList: data.processList
                });
            }
        });
    },

    /** 生命周期函数--监听页面初次渲染完成 */
    onReady: function () {},

    /** 生命周期函数--监听页面显示 */
    onShow: function () {
        let self = this;
        self.queryProcessList();
    },

    /** 生命周期函数--监听页面隐藏 */
    onHide: function () {},

    /** 生命周期函数--监听页面卸载 */
    onUnload: function () {},

    /** 页面相关事件处理函数--监听用户下拉动作 */
    onPullDownRefresh: function () {
        let self = this;
        // 查询工序列表
        self.queryProcessList();
    },

    /** 页面上拉触底事件的处理函数 */
    onReachBottom: function () {},

    /** 用户点击右上角分享 */
    onShareAppMessage: function () {}
});
